/**
 * 移除打包注释插件
 */
class RemoveCommentsPlugin {
    constructor() {}
    apply(complier) {
        console.log('=================================')
        console.log('=================================')
        console.log('RemoveCommentsPlugin start...')
        complier.hooks.emit.tap('RemoveCommentsPlugin', compilation => {
            for (const name in compilation.assets) {
                if (name.endsWith('.js')) {
                    const content = compilation.assets[name].source()
                    const temp = content.replace(/\/\*{2,}\/\s?/g, '')
                    compilation.assets[name] = {
                        source: () => temp,
                        size: () => temp.length,
                    }
                }
            }
            console.log('RemoveCommentsPlugin finish...')
            console.log('=================================')
            console.log('=================================')
        })
    }
}

module.exports = RemoveCommentsPlugin